﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
namespace AlbonWeb.Manager.AccountManager
{
    public partial class UserDetails : System.Web.UI.Page
    {
        private readonly BLL.UserBLL userbll = new BLL.UserBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["Back"] = Request.UrlReferrer.ToString();
                //绑定国家信息
                string cmdstr = "select * from Country";
                SqlHelper.BindDropDownList(ddlCountry, "countryName", "ID", SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null);
                //加载信息
                initUserDetail(Request["userid"].ToString());
            }
        }

        //加载用户的详细信息
        private void initUserDetail(string userid)
        {
            DataTable dt = userbll.getUserByID(userid);
            trueName.Text = dt.Rows[0]["trueName"].ToString();
            ddlCountry.SelectedValue = dt.Rows[0]["countryID"].ToString();
            companyName.Text = dt.Rows[0]["companyName"].ToString();
            phoneNo.Text = dt.Rows[0]["phoneNo"].ToString();
            address.Text = dt.Rows[0]["userAddress"].ToString();
            email.Text = dt.Rows[0]["email"].ToString();
        }

        //提交信息
        protected void UserDetail_Modify_Click(object sender, EventArgs e)
        {
            Albon.Model.UserAccount user = new Albon.Model.UserAccount();
            user.ID = int.Parse(Request["userid"].ToString());
            user.trueName = trueName.Text.Trim();
            user.countryID = int.Parse(ddlCountry.SelectedValue);
            user.companyName = companyName.Text.Trim();
            user.phoneNo = phoneNo.Text.Trim();
            user.userAddress = address.Text.Trim();
            user.email = email.Text.Trim();
            userbll.updateUser(user);
            Response.Redirect(ViewState["Back"].ToString());
        }
    }
}